function showSuccessUI(msg){
	//ui.notify(msg).sticky().type('alert-success').hide(5000).effect('slide');
}
function showDangerUI(msg){
	alert(msg);
	//ui.notify(msg).sticky().type('alert-danger').hide(5000).effect('slide');
}


function getObjectURL(file) {
	var url;
	if (navigator.userAgent.indexOf("MSIE")>=1) { // IE
		file.select();
		url = document.selection.createRange().text;
	} else{
		url = window.URL.createObjectURL(file);
	}
	return url;
};

function getDuration(file,callback){
	var url = getObjectURL(file);
	var video = document.createElement("VIDEO");
	video.src = url;
	$("body").append(video);
	$(video).hide(0);
	var t = setInterval(function(){
		if(video.duration > 0){
			//获取到视频时长，关闭定时器
			clearInterval(t);
			//修改input的值
			callback(Math.ceil(video.duration));
			//溢出元素
			$(video).remove();
		}
	},100);
}

//获取文件上传的路径
function getPath(hash,fileName){
	var timestamp = Date.parse(new Date());
	timestamp = timestamp / 1000;
	var date = new Date();
	//获取后缀名
	var suffix=fileName.match(/\.(\w+)$/);
	suffix = suffix[0];

	return 'ad/'+date.getFullYear()+'/'+(date.getMonth()+1)+'/'+hash+suffix;
}

//获取文件的hash值
function fileMd5(file,callback){
	var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
	var chunkSize = 2097152; //读取时分割文件 按每一块2MB分割
	var chunks = Math.ceil(file.size / chunkSize);
	var currentChunk = 0;
	var spark = new SparkMD5.ArrayBuffer();

	function loadNext() {
		var fileReader = new FileReader();
		fileReader.onload = function(e){
			spark.append(e.target.result); // 追加数组缓冲区
			currentChunk++;
			if (currentChunk < chunks){
				loadNext();
			}else{
				callback(spark.end());
			}
		};
		fileReader.onerror = function () {
			showDangerUI("计算文件MD5出现问题");
		};
		var start = currentChunk * chunkSize,
			end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
		fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
	};
	loadNext();
}